//
//  COCOAFANCell.m
//  CocoaFan
//
//  Created by Chen Xianan on 2/16/09.
//  Copyright 2009 realazy.org All rights reserved.
//

#import "COCOAFANCell.h"
#import "COCOAFANViewController.h"
#import "COCOAFANBubbleView.h"

@implementation COCOAFANCell

@synthesize controller, statusContent, selected;

- (void)setSelected:(BOOL)sel
{
	selected = sel;
	[controller setSelected:sel];
	[[controller bubbleView] setSelected:sel];
}

- (id)initWithStatusContent:(NSDictionary *)statusContent_
{
	if (self = [super init]){
		[self setStatusContent:statusContent_];
		controller = [[COCOAFANViewController alloc] init];
		[controller setStatusContent:[self statusContent]];
		
		return self;
	}
	return nil;
}

- (void)dealloc
{
	[controller release];
	[self setStatusContent:nil];
    [super dealloc];
}

- (void)drawWithFrame:(NSRect)cellFrame
			   inView:(NSView *)controlView
{
    [super drawWithFrame:cellFrame inView:controlView];
	[controller setSelected:[self isSelected]];
	
	NSView *view = [controller view];
    [view setFrame:cellFrame];
	
    if ([view superview] != controlView)
		[controlView addSubview:view];	
}

#pragma mark NSCopying protocol

- (id)copyWithZone:(NSZone *)zone
{
	COCOAFANCell *copy = [super copyWithZone:zone];
	copy->statusContent = [[self statusContent] retain];
	copy->controller = [[self controller] retain];
	return copy;
}

@end
